package com.geeyuu.android.databases;

import com.geeyuu.android.model.BaseUserInfo;
import com.geeyuu.android.model.ChatInfo;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class GeeSQLite extends SQLiteOpenHelper{
    
    private static final String DATABASE_NAME = "geeyuu.db";
    private static final int VERSION = 1;
    private boolean isClosed = false;

    public GeeSQLite(Context context, String name, CursorFactory factory, int version) {
        super(context, DATABASE_NAME, null, VERSION);
        isClosed = false;
    }
    
    @Override
    public synchronized void close() {
        isClosed = true;
        super.close();
    }
    
    public boolean isClosed(){
        return isClosed;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        
        db.execSQL(
                "CREATE TABLE " + BaseUserInfo.TABLE_NAME + " ("
                + BaseUserInfo.EXTRA_UID + " INTEGER PRIMARY KEY NOT NULL,"
                + BaseUserInfo.EXTRA_AGE + " INTEGER,"
                + BaseUserInfo.EXTRA_DISTANCE + " REAL,"
                + BaseUserInfo.EXTRA_HEIGHT + " INTEGER,"
                + BaseUserInfo.EXTRA_IS_GUEST + " INTEGER,"
                + BaseUserInfo.EXTRA_IS_ONLINE + " INTEGER,"
                + BaseUserInfo.EXTRA_LAST_ALBUM_MODIFY_TIME + " INTEGER,"
                + BaseUserInfo.EXTRA_LAST_ONLINE_TIME + " INTEGER,"
                + BaseUserInfo.EXTRA_LAST_MODIFY_TIME + " INTEGER,"
                + BaseUserInfo.EXTRA_LON_AND_LAT + " TEXT,"
                + BaseUserInfo.EXTRA_MAIN_PHOTO_ID + " TEXT,"
                + BaseUserInfo.EXTRA_NICK_NAME + " TEXT,"
                + BaseUserInfo.EXTRA_POP_VALUE + " INTEGER,"
                + BaseUserInfo.EXTRA_PRIVATE_PHOTO_IDS + " TEXT,"
                + BaseUserInfo.EXTRA_PUBLIC_PHOTO_IDS + " TEXT,"
                + BaseUserInfo.EXTRA_SIGN + " TEXT,"
                + BaseUserInfo.EXTRA_ROLE + " INTEGER,"
                + BaseUserInfo.EXTRA_WEIGHT + " INTEGER,"
                + BaseUserInfo.EXTRA_VISIT_TIMES + " TEXT,"
                + BaseUserInfo.EXTRA_MONEY + " INTEGER,"
                + BaseUserInfo.EXTRA_VISITOR_IDS + " TEXT,"
                + BaseUserInfo.EXTRA_ACCOUNT_NAME + " TEXT,"
                + BaseUserInfo.EXTRA_ATTENTION_MODIFY_TIME + " INTEGER,"
                + BaseUserInfo.EXTRA_PRIVATE_ALBUM_MODIFY_TIME + " INTEGER,"
                + BaseUserInfo.EXTRA_SHARE_MODIFY_TIME + " INTEGER,"
                + BaseUserInfo.EXTRA_MY_FANS_COUNT + " INTEGER,"
                + BaseUserInfo.EXTRA_BLACK_MODIFY_TIME + " INTEGER"
                + ");"
                );
        
        db.execSQL(
                "CREATE TABLE " + ChatInfo.TABLE_NAME + " ("
                + ChatInfo.CHAT_ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
                + ChatInfo.FRIEND_UID + " INTEGER,"
                + ChatInfo.SEND_UID + " INTEGER,"
                + ChatInfo.RECEIVE_UID + " INTEGER,"
                + ChatInfo.CHAT_CONTENT + " TEXT,"
                + ChatInfo.SEND_DATE + " INTEGER,"
                + ChatInfo.MSG_TYPE + " INTEGER,"
                + ChatInfo.CHAT_SEND_STATE + " INTEGER,"
                + ChatInfo.VOICE_PLAY_STATE + " INTEGER,"
                + ChatInfo.CHAT_MARK_ID + " INTEGER,"
                + ChatInfo.VOICE_FILE_ID + " TEXT,"
                + ChatInfo.LON_AND_LAT + " TEXT"
                + ");"
                );
        
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        
    }

}




























